using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class EventDispathcer {

	// Use this for initialization
	Dictionary<uint,RegistFunction> m_dispathcerMap = new Dictionary<uint, RegistFunction>();
	public void RegistEvent(uint EventID,RegistFunction pFunction)
	{	
		RegistFunction rf;
		if(!m_dispathcerMap.TryGetValue(EventID, out rf))
        {
			m_dispathcerMap.Add(EventID, pFunction);
			return;
		}
		rf += pFunction;
	}
	public void UnRegistEvent(uint EventID,RegistFunction pFunction)
	{
		RegistFunction rf;
		if (m_dispathcerMap.TryGetValue(EventID, out rf))
		{
			rf -= pFunction;
		}
	}
	public void HandleEvent(uint EventID,object pSender)
	{
		RegistFunction rf;
		if (m_dispathcerMap.TryGetValue(EventID, out rf))
		{
			if(rf != null)
				rf(pSender);
		}
	}
}